package com.miles.test;

import com.miles.Mapper.StudentMapper;
import com.miles.Mapper.TeacherMapper;
import com.miles.pojo.Student;
import com.miles.pojo.Teacher;
import com.miles.util.MybatisUntil;
import org.junit.Test;

import java.util.List;

public class SqlSelect {
    @Test
    public void  selectAllTeacher(){
        TeacherMapper mapper = MybatisUntil.getSqlSession().getMapper(com.miles.Mapper.TeacherMapper.class);
        List<Teacher> teachers = mapper.selectAll();
        for (Teacher t: teachers) {
            System.out.println(t.getId()+"=="+t.getName());
        }
    }

    @Test
    public  void selectAllStudent(){
        StudentMapper mapper = MybatisUntil.getSqlSession().getMapper(com.miles.Mapper.StudentMapper.class);
        List<Student> students = mapper.selectAllStudent();
        for (Student stu: students) {
            System.out.println(stu.getId()+"=="+stu.getName());
        }
    }
    @Test
    public  void selectStuTeacher(){
        StudentMapper mapper = MybatisUntil.getSqlSession().getMapper(com.miles.Mapper.StudentMapper.class);
        List<Student> students = mapper.selectStuTeacher();
        for (Student s: students ) {
            System.out.println(s.getId()+"=="+s.getName()+"=="+s.getTeacher().getName());
        }
    }
    @Test
    public void  selectStuTeacher1(){
        StudentMapper mapper = MybatisUntil.getSqlSession().getMapper(StudentMapper.class);
        List<Student> students = mapper.selectStuTeacher1();
        for (Student s : students) {
            System.out.println(s.getId()+"=="+s.getName()+"==="+s.getTeacher().getName());
        }
    }

    @Test
    public void selectByID(){
        TeacherMapper mapper = MybatisUntil.getSqlSession().getMapper(TeacherMapper.class);
        Teacher teacher = mapper.selectByID(1);
        for (Student s :teacher.getStudents()) {
            System.out.println(teacher.getId()+"==="+s.getTid()+"=="+teacher.getName()+"=="+s.getId()+"=="+s.getName());
        }
    }

    @Test
    public void selectByID1(){
        TeacherMapper mapper = MybatisUntil.getSqlSession().getMapper(com.miles.Mapper.TeacherMapper.class);
        Teacher teacher = mapper.selectByID1(1);
        for (Student s :teacher.getStudents()) {
            System.out.println(teacher.getId()+"=="+teacher.getName()+"=="+s.getId()+"=="+s.getName());
        }
    }
}
